<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="110px">
      <el-form-item label="订单号" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入订单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申请用户" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入申请用户名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="提现账户名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入提现账户名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择审核状态" clearable size="small">
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:getcash:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
		      :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['system:getcash:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="getcashList" border size="mini" stripe @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键id" align="center" prop="id" v-if="false"/>
      <el-table-column label="订单号" align="center" prop="orderNo" width="180"/>
      <el-table-column label="申请用户" align="center" prop="userName" />
      <el-table-column label="申请金额" align="center" prop="applyPrice" >
        <template slot-scope="scope">
          <span  >{{scope.row.applyPrice / 100}}元</span>
        </template>
      </el-table-column>
      <el-table-column label="提现金额" align="center" prop="extractPrice">
        <template slot-scope="scope">
          <span  >{{scope.row.extractPrice / 100}}元</span>
        </template>
      </el-table-column>
      <el-table-column label="支付宝订单号" align="center" prop="extractId" width="235"/>
      <el-table-column label="支付宝资金流水号" align="center" prop="payFundId" width="235"/>
      <el-table-column label="支付渠道" align="center" prop="extractChannel" />
      <el-table-column label="提现账户名" align="center" prop="name" width="100"/>
      <el-table-column label="提现账号" align="center" prop="account" width="110"/>
      <el-table-column label="审核状态" align="center" prop="status" :formatter="statusFormat" width="100" >
        <template slot-scope="scope">
          <span v-if="scope.row.status == 1 " style="color: red">审核中</span>
          <span v-if="scope.row.status == 2 " style="color: green">审核通过</span>
          <span v-if="scope.row.status == 3 " style="color: gray">审核未通过</span>
        </template>
      </el-table-column>
      <el-table-column label="审核说明" align="center" prop="checkDes" />
      <el-table-column label="申请时间" align="center" prop="createtime" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createtime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核时间" align="center" prop="updatetime" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updatetime, '{y}-{m}-{d}  {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" fixed="right" width="120" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)" v-if="scope.row.status != 2"
            v-hasPermi="['system:getcash:edit']"
          >审核</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改提现记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="60%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules"   label-width="120px">
        <el-form-item label="订单号" prop="orderNo">
          <el-input v-model="form.orderNo" disabled placeholder="请输入订单号" />
        </el-form-item>
        <el-form-item label="申请用户id" prop="userName">
          <el-input v-model="form.userName" disabled placeholder="请输入申请用户" />
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" disabled placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="提现账号" prop="account">
          <el-input v-model="form.account" disabled placeholder="请输入提现账号" />
        </el-form-item>
        <el-form-item label="支付渠道" prop="extractChannel">
          <el-input v-model="form.extractChannel" disabled placeholder="请输入支付渠道" />
        </el-form-item>
        <el-form-item label="申请金额" prop="applyPrice">
          <el-input v-model="form.applyPrice" disabled placeholder="请输入申请金额" />
        </el-form-item>
        <el-form-item label="提现金额" prop="extractPrice">
          <el-input v-model="form.extractPrice" disabled placeholder="请输入提现金额" />
        </el-form-item>
        <el-form-item label="申请时间" prop="createtime">
          <el-date-picker clearable size="small" disabled
            v-model="form.createtime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择申请时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="审核状态" prop="status">
          <el-select v-model="form.status" placeholder="请选择审核状态">
            <el-option
              v-for="dict in statusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审核说明" prop="checkDes">
          <el-input v-model="form.checkDes" placeholder="请输入审核说明" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listGetcash, getGetcash, delGetcash, addGetcash, updateGetcash, exportGetcash } from "@/api/system/getcash";

export default {
  name: "Getcash",
  components: {
  },
  data() {
    return {
	  //按钮loading
	  buttonLoading: false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 提现记录表格数据
      getcashList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 审核状态字典 ：1审核中，2审核通过，3审核未通过
      statusOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderNo: undefined,
        userName: undefined,
        status: undefined,
        name: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        status: [
          { required: true, message: "审核状态不能为空", trigger: "change" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("getcash_status").then(response => {
      this.statusOptions = response.data;
    });
  },
  methods: {
    /** 查询提现记录列表 */
    getList() {
      this.loading = true;
      listGetcash(this.queryParams).then(response => {
        this.getcashList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 审核状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        orderNo: undefined,
        userId: undefined,
        status: undefined,
        applyPrice: undefined,
        extractPrice: undefined,
        extractId: undefined,
        payFundId: undefined,
        extractChannel: undefined,
        name: undefined,
        account: undefined,
        checkDes: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加提现记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids
      getGetcash(id).then(response => {
        this.loading = false;
        this.form = response.data;
        this.form.applyPrice = this.form.applyPrice / 100;
        this.form.extractPrice = this.form.extractPrice / 100;
        this.open = true;
        this.title = "修改提现记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.applyPrice = this.form.applyPrice * 100;
          this.form.extractPrice = this.form.extractPrice * 100;
          this.buttonLoading = true;
          updateGetcash(this.form).then(response => {
            this.buttonLoading = false;
            this.msgSuccess("操作成功");
            this.open = false;
            this.getList();
          });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除提现记录编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.loading = true;
          return delGetcash(ids);
        }).then(() => {
          this.loading = false;
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有提现记录数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportGetcash(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
